package t4tools.etodo.editor;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.forms.widgets.Form;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.part.EditorPart;

import t4tools.etodo.model.Todo;

public class TodoEditor extends EditorPart {

	public static final String ID = "t4tools.etodo.todoEditor";
	private Todo todo;

	private FormToolkit toolkit;
	private Form form;

	// Will be called before createPartControl
	@Override
	public void init(IEditorSite site, IEditorInput input) throws PartInitException {
		if (!(input instanceof TodoEditorInput)) {
			throw new RuntimeException("Wrong input");
		}

		setSite(site);
		setInput(input);
		todo = ((TodoEditorInput) input).getTodo();
		setPartName("TODO: " + todo.getName());
	}

	@Override
	public void createPartControl(Composite parent) {
		toolkit = new FormToolkit(parent.getDisplay());
		form = toolkit.createForm(parent);
		form.setText("Hello, Eclipse Forms");
		toolkit.decorateFormHeading(form);

		// GridLayout layout = new GridLayout();
		// layout.numColumns = 2;
		// parent.setLayout(layout);
		//
		// Label label1 = new Label(parent, SWT.NONE);
		// label1.setText("Title");
		// Text text = new Text(parent, SWT.BORDER);
		// text.setText(todo.getName());
		// text.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true,
		// false));

	}

	@Override
	public void doSave(IProgressMonitor monitor) {
		// person.getAddress().setCountry(text2.getText());
	}

	@Override
	public void doSaveAs() {
	}

	@Override
	public boolean isDirty() {
		return false;
	}

	@Override
	public boolean isSaveAsAllowed() {
		return false;
	}

	@Override
	public void setFocus() {
	}

	@Override
	public void dispose() {
		toolkit.dispose();
		super.dispose();
	}
}
